﻿using AlarmClock.BLL;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AlarmClock.UI
{
    static class Program
    {
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var runningProcess = Service.GetExistProcess();
            if (runningProcess != null) //同名程序已经在运行
            {
                IntPtr mainWindowHandle1 = runningProcess.MainWindowHandle;
                if (mainWindowHandle1 == IntPtr.Zero)//窗口被隐藏了
                {
                    //目标窗体的 Text 属性中的字符串
                    mainWindowHandle1 = PPWin32.FindWindow(null, "闹钟");
                }
                PPWin32.ShowWindowAsync(mainWindowHandle1, 1);
                PPWin32.SetForegroundWindow(mainWindowHandle1);
            }
            else
            {
                Application.Run(new MainForm());
            }

        }
    }
}
